﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DBUpdater
{
    public partial class MainForm
    {

        private bool _drag;
        private Point _startPoint = new Point(0, 0);

        private void Form1_Load(object sender, EventArgs e)
        {
            //menuStrip1.BackColor = Color.FromArgb(0, 152, 226);
            menuStrip1.MouseDown += Form1_MouseDown;
            menuStrip1.MouseUp += Form1_MouseUp;
            menuStrip1.MouseMove += Form1_MouseMove;
            fileList.MouseDown += Form1_MouseDown;
            fileList.MouseUp += Form1_MouseUp;
            fileList.MouseMove += Form1_MouseMove;
            fileList.Columns.Add("File name");
            var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.csv", SearchOption.TopDirectoryOnly);
            foreach (var file in files)
            {
                var split = file.Split('\\');
                var name = split[split.Length - 1];
                if (name != "access.csv" &&
                    name != "regions.csv" &&
                    name != "stations.csv" &&
                    name != "blr.csv")
                    continue;
                fileList.Items.Add(split[split.Length - 1]);
            }
            fileList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            fileList.Scrollable = false;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void updateToolStripMenuItem_MouseEnter(object sender, EventArgs e)
        {
            ((ToolStripMenuItem)sender).ForeColor = Color.Black;
        }

        private void updateToolStripMenuItem_MouseLeave(object sender, EventArgs e)
        {
            ((ToolStripMenuItem)sender).ForeColor = Color.White;
        }

        private void menuToolStripMenuItem_MouseEnter(object sender, EventArgs e)
        {
            ((ToolStripMenuItem)sender).ForeColor = Color.Black;
        }

        private void menuToolStripMenuItem_MouseLeave(object sender, EventArgs e)
        {
            ((ToolStripMenuItem)sender).ForeColor = Color.White;
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            //
            //On Mouse Down set the flag drag=true and
            //Store the clicked point to the start_point variable
            //
            _drag = true;
            _startPoint = new Point(e.X, e.Y);
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            //
            //Set the drag flag = false;
            //
            _drag = false;
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            //
            //If drag = true, drag the form
            //
            if (_drag)
            {
                var p1 = new Point(e.X, e.Y);
                Point p2 = PointToScreen(p1);
                var p3 = new Point(p2.X - _startPoint.X,
                                        p2.Y - _startPoint.Y);
                Location = p3;
            }
        }

    }
}
